package com.njupt.yanglonglong.report.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njupt.yanglonglong.report.demo.dto.StudentGradeDto;
import com.njupt.yanglonglong.report.demo.dto.StudentsGradeDto;
import com.njupt.yanglonglong.report.demo.entity.Report;
import com.njupt.yanglonglong.report.demo.entity.ScoreVO;
import com.njupt.yanglonglong.report.demo.service.ReportService;
import com.njupt.yanglonglong.report.demo.mapper.ReportMapper;
import com.njupt.yanglonglong.report.demo.vo.ReportVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 */
@Service
public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report>
        implements ReportService {
    @Autowired
    private ReportMapper reportMapper;

    @Override
    public List<ReportVO> getReportListByExperId(String experimentId) {
        return reportMapper.getReportListByExperId(experimentId);
    }

    @Override
    public List<ReportVO> getCommittedReportListByExperId(String experimentId) {
        return reportMapper.getCommittedReportListByExperId(experimentId);
    }

    @Override
    public Report getReportByStudentIdExperimentId(String studentId, String experimentId) {
        QueryWrapper<Report> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("stu_id", studentId).eq("exper_id", experimentId);
        Report report = reportMapper.selectOne(queryWrapper);
        return report;
    }

    @Override
    public List<StudentsGradeDto> queryGradeByTeacherCourseId(String teacherId, String courseId) {
        return reportMapper.queryGradeByTeacherCourseId(teacherId, courseId);
    }

    @Override
    public List<StudentGradeDto> queryStudentGradeByStuIdAndCourseId(String studentId, String courseId) {
        return reportMapper.queryStudentGradeByStuIdAndCourseId(studentId, courseId);
    }

    @Override
    public Boolean stuInsertReportFile(Report report) {
        report.setStatus(2);
        reportMapper.insert(report);
        return true;
    }

    @Override
    public Boolean stuUpdateReportFile(Report report) {
        reportMapper.stuUpdateReportFile(report);
        return true;
    }

    @Override
    public Boolean markReport(Report report) {
        try {
            report.setStatus(3);
            reportMapper.updateById(report);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public Report getMarkedInfo(Report report) {
        QueryWrapper qw = new QueryWrapper();
        qw.eq("id", report.getId());
        return reportMapper.selectOne(qw);
    }

    @Override
    public List<Report> getReportByStudentIdCourseId(String stuId, String courseId) {
        return reportMapper.getReportByStuIdAndCourseId(stuId, courseId);
    }

    @Override
    public List<ScoreVO> getReportScoreByStuIdAndCourseId(String stuId, String courseId) {
        return reportMapper.getReportScoreByStuIdAndCourseId(stuId, courseId);
    }
}
